﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class admin_edprotylang : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("select * from producttype_lang where id = @id and lang = @lang", cn);
        mySqlSelect.CommandType = CommandType.Text;
        SqlParameter paramid = new SqlParameter("@id", SqlDbType.BigInt);
        paramid.Value = Request.Params["id"];
        mySqlSelect.Parameters.Add(paramid);
        SqlParameter paramlg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
        paramlg.Value = Request.Params["lang"];
        mySqlSelect.Parameters.Add(paramlg);
        try
        {
            SqlDataReader rd = mySqlSelect.ExecuteReader();
            if (rd.HasRows)
            {
                rd.Read();
                //lang.SelectedValue = rd.GetSqlString(1).ToString();
                menu.Text = rd.GetSqlString(2).ToString();
            }
            rd.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            cn.Close();
            Console.WriteLine("Loi setValueFromDatabaseToForm : " + ex);
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("update producttype_lang set menu = @menu where (id = @id) and (lang = @lang)", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter me = new SqlParameter("@menu", SqlDbType.NVarChar, 50);
        me.Value = menu.Text;

        SqlParameter id = new SqlParameter("@id", SqlDbType.BigInt);
        id.Value = Request.QueryString["id"];

        SqlParameter lg = new SqlParameter("@lang", SqlDbType.NVarChar, 2);
        lg.Value = Request.QueryString["lang"]; ;

        mySqlSelect.Parameters.Add(me);
        mySqlSelect.Parameters.Add(id);
        mySqlSelect.Parameters.Add(lg);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?page=qlprotylang&id=" + Request.QueryString["id"].ToString());
    }
}